<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/myStrategyComment.css"/>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/common.js"></script>
		<script>
            $(function () {
                //禁用深度递归
                jQuery.ajaxSettings.traditional = true;
                //获取目录id
                var params=getParams();
                //根据目录id获取骡友点评前6的标签
                $.get("/strategies/"+params.id+"/tags",{pageSize:6},function (data) {
                    $(".tag").renderValues(data)
                });
                //评级星数
                var num;
                //定义星星图标自定义属性，绑定点击事件，进行类的变更
                $(".comment .star i").click(function () {
                    //拿到所有的star
                    var arr=$(".comment .star i");
                    //回复出厂设置
                    $(".comment .star i").removeClass("fa-star").addClass("fa-star-o");
                    //拿到点击的星星图标自定义属性值
                    num=$(this).data("num");
                    //循环添加'fa-star'类
                    for (var i=0;i<num;i++) {
                        $(arr[i]).removeClass("fa-star-o").addClass("fa-star");
                    }
                });
                var rect;

                //上传图片，绑定上传图片点击事件，提交上传图片
                $(".comment .imgs .rect").click(function () {
                    rect = $(this);
                    $("#fileInput").click();

                });
                //绑定文件上传值改变事件
                $("#fileInput").change(function () {
                    if ($("#fileInput").val()) {
                        $("#fileForm").ajaxSubmit(function (data) {
                            //回显图片
                            rect.html("<img src='"+data.url+"'/>")
                        });
                    }
                });
                //绑定点击事件，提交表单，并提交数据
                $("#submitBtn").click(function () {
                    //定义数据提交的json对象，用于提交
                    var json = {};
                    //星级
                    json.starNum = num;
                    //定义标签数组tags，用以封装tag标签
                    var tags = [];
                    //系统标签
                    var inputs=$(".tag label.active input");
                    var index=inputs.length;
                    for (var i=0;i<index;i++) {
                        tags[i]=$(inputs[i]).val();
                    }
                    //自定义标签
                    var myTag=$(".tag input[name='myTags']").val();
                    var myTagArr=myTag.split(" ");
                    for (var i=0;i<myTagArr.length;i++) {
                        if (myTagArr[i]!="") {
                            tags[index++] = myTagArr[i];
                        }
                    }
                    json.tags = tags;
                    //评价内容
                    json.content=$("textarea[name='content']").val();
                    //图片
                    var imgUrls = "";
                    var imgArr=$(".imgs img");
                    for (var i=0;i<imgArr.length;i++) {
                        imgUrls += $(imgArr[i]).attr("src") + ";";
                    };
                    console.log(imgUrls);
                    json.imgUrls = imgUrls;
                    $.post("/strategies/"+params.id+"/comments", json, function (data) {
                        if (data.success) {
                            window.history.go(-1);
                        }
                    });
                });
            })
		</script>
	</head>

	<body>
    <form action="/images" method="post" enctype="multipart/form-data" id="fileForm">
        <!--隐藏文件框，用于上传封面-->
        <input id="fileInput" type="file" name="file" style="display: none">
    </form>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="javascript:window.history.go(-1)">
					<span><i class="fa fa-chevron-left" ></i></span>
				</a>

			</div>
			<div class="col">
				<span>点评</span>
			</div>
			<div class="col"></div>
		</div>
	</div>

	<div class="comment">
		<div class="container star">
			<p>你对该旅游地的评价</p>
			<i class="fa fa-star-o fa-lg" data-num="1"></i>
			<i class="fa fa-star-o fa-lg" data-num="2"></i>
			<i class="fa fa-star-o fa-lg" data-num="3"></i>
			<i class="fa fa-star-o fa-lg" data-num="4"></i>
			<i class="fa fa-star-o fa-lg" data-num="5"></i>
		</div>
		<hr />
		<div class="container tag">
			<p>请为该旅游地选择合适的标签（大家都在评）</p>
			<div class="btn-group-toggle" data-toggle="buttons" render-loop="list">
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" render-value="list.name"> <span render-html="list.name"></span>
				</label>
			</div>

			<p>添加你自己的标签</p>
			<input name="myTags" class="form-control"  placeholder="请使用空格隔开标签，每个标签不超8个字"   />

			<p>更多评价内容</p>
			<textarea name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
		</div>
		<div class="container imgs ">
			<p>上传图片</p>

			<div class="row">
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
			</div>
		</div>
	</div>



	<div class="operation">
		<button class="btn" onclick="window.history.go(-1)">放弃评价</button>
		<button class="btn" id="submitBtn">提交评价</button>
	</div>





	</body>


</html>